<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('没有找到该任务，请重新选择！','error');
	}
	$item=pdo_get('jy_aihire_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$item['images']=$item['images']?json_decode($item['images'],true):array();
	$pidcode='red_'.$item['type'].'_'.$id;
	$merch = pdo_get('jy_aihire_merch',array('id'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']));
	$merch['pcd']=json_decode($merch['pcd'],true);
	$item['address']=$item['address']?:$merch['address'];
	pdo_update('jy_aihire_job',array('looks +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	//进入作品详情，记录访问者浏览信息
	$islook=pdo_get('jy_aihire_looklog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'jobid'=>$id));
	if(empty($islook) || $islook['createtime']<TIMESTAMP-3600){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'jobid'=>$id,
			'mid'=>$_SESSION['uid'],
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_aihire_looklog',$insert);
	}
	$return['sex']=array('0'=>'','1'=>'男','2'=>'女');
	$return['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
	$item['createtime']=$item['createtime']?date('Y-m-d H:i:s',$item['createtime']):'';
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$lat_lng=$this->session('lat_lng');	
	$item['onlinetime']=json_decode($item['onlinetime'],true);
	if($lat_lng && $item['lat_lng']['lng'] && $item['lat_lng']['lat']){
				$item['juli']=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$item['lat_lng']['lng'],$item['lat_lng']['lat']);
				$item['juli']=price($item['juli']/1000,'ini');
	}
	$item['member']=pdo_get('core_members',array('id'=>$item['mid']));
	$item['images']=json_decode($item['images'],true);
	$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
	$item['baotypetitle']=$this->job_paytype2[$item['paytype']].'结('.$this->job_baotype[$item['baotype']].'版)';
	$item['content'] = json_decode($item['content'],true);
	$item['sextitle']=$this->sex2[$item['sex']];
	$item['educationidtitle']=$this->xueli_type2[$item['educationid']];
	$item['fee']=0;
	if($item['content']){
		foreach($item['content'] as &$row){
			if($row['type']==1){
				$item['desc'] = $row['data'];
			}
		}
	}
	$this->session('id',$_RQ['id']);
	
	$return['xueli_type']=$this->xueli_type;
	$return['merch']=$merch;
	$return['item']=$item;
	$return['params']['merchid']=$item['merchid'];
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['remark'],
		'link'=>custom_url('jy_aihire/job_detail//id='.$item['id'].'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>tomedia($item['images'][0]),
	);
	set_html('title',$item['title']);
	exi($return);
}

if($_RQ['op']=='shoucang'){
	$id = $this->session('id');
	if(!$id){
		exi('没有找到该作品，请重新选择！','error');
	}
	$item=pdo_get('jy_aihire_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$shoucang=pdo_get('jy_aihire_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
	if($shoucang){
		if($shoucang['isshoucang'] !=1){
			pdo_update('jy_aihire_shoucang',array('isshoucang'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
			exi('收藏成功');
		}else{
			pdo_update('jy_aihire_shoucang',array('isshoucang'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
		   exi('取消收藏');
		}
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'pid'=>$id,
			'mid'=>$_SESSION['uid'],
			'isshoucang'=>1,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_aihire_shoucang',$insert);
	}
	exi('收藏成功');
}
if($_RQ['op']=='like'){
	$id = $this->session('id');
	$postdata=get_postdata();
	if(!$id){
		exi('没有找到该作品，请重新选择！','error');
	}
	$looklist=pdo_get('jy_aihire_job_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
	if($looklist){
		if($looklist['islike'] !=1){
			pdo_update('jy_aihire_job',array('like +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			pdo_update('jy_aihire_job_like',array('islike'=>1),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
			
		}elseif($postdata['like'] !=1){
			pdo_update('jy_aihire_job',array('like -='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			pdo_update('jy_aihire_job_like',array('islike'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
		}
	}
	exi('点赞成功');
}
if($_RQ['op']=='bookjob'){
	$_SESSION['memberid']=$this->model('member')->checkmember();
	$this->model('member')->checkinfo();
	$this->model('member')->checkshiming();
	$id=$_RQ['jobid'];
	$job=pdo_get('jy_aihire_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if(!$job){
		exi('没有找到该任务，请重新选择！'.$id,'error');
	}
	$job_log=pdo_get('jy_aihire_job_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'jobid'=>$job['id'],'status'=>array(0,1)));
	if($job_log['id']){
		exi('您有一个该任务的申请还在处理中！','error');
	}
	$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'memberid'=>$_SESSION['memberid'],
			'mid'=>$_SESSION['uid'],
			'merchid'=>$job['merchid'],
			'jobid'=>$job['id'],
			'type'=>$job['type'],
			'comment'=>'应聘：'.$job['title'],
			'createtime'=>TIMESTAMP,
	);
	pdo_insert('jy_aihire_job_log',$insert);
	$id=pdo_insertid();
	exi('提交成功','','/job_log/');
}